﻿namespace FlashcardPdfCreator
{
	using System.Collections.Generic;
	using System.IO;
	using System;

	public class CsvStreamReaderCardDataProvider : IDisposable
	{
		CsvStreamReader reader = null;

		public CsvStreamReaderCardDataProvider(MemoryStream stream)
		{
			this.reader = new CsvStreamReader(stream);
		}

		public IEnumerable<ICardData> GetCardData(char delimeter = ';')
		{
			this.reader.Delimiter = delimeter;
			CsvRow row = new CsvRow();

			while (this.reader.ReadRow(row))
			{
				//if (row.Count < 4)
				//    continue;

				CsvStreamReaderCardData card = new CsvStreamReaderCardData(row);

				yield return card;
			}
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}
		protected virtual void Dispose(bool disposing)
		{
			if (disposing)
			{
				this.reader.Dispose();
				this.reader = null;
			}

		}

		~CsvStreamReaderCardDataProvider()
		{

			Dispose(false);
		}
	}
}
